@extends('admin.layout.layout', ['row' => @$page])

@section('contain')

    <style>
        .table .tth{
            background-color: rgba(0, 0, 0, 0.05);
            width: 150px;
            font-weight: bold;
        }
        .table .ttd{
            width: 350px;
        }
        .table .ttt{
            padding: 0;
        }
        .ttt .table{
            margin: 0;
        }
        .ttt .table img + p{
            text-align: center;
            margin: 10px 0 0;
        }
        .tst{
            color: #00b050;
            font-weight: 700;
            text-align: center;
            font-size: 1.25rem;
        }
    </style>

    <div class="portlet">
        <div class="portlet-title">
            <div class="caption">
                <x-portlet-breadcrumb :page="$page"></x-portlet-breadcrumb>
            </div>
            <div class="actions"></div>
        </div>

        <form action="/{{ request()->path() }}/" method="post" onsubmit="return checkVal(this)" class="precut-form t-right">
            @csrf
            <input type="text" name="_previous_" value="{{ request()->header('referer') }}" hidden>


            <table class="table s3">
                <tbody>
                <tr>
                    <td class="tth">{{ ts('AZFS') }}</td>
                    <td class="ttd">
                        <input type="text" readonly value="{{ ts('tcaz') }}" class="form-control">
                    </td>
                    <td colspan="4" class="text-danger">{{--{{ ts('wcit3') }}--}}</td>
                </tr>
                <tr>
                    <td colspan="6" class="tst">{{ ts('CUSTOMER') }}</td>
                </tr>
                <tr>
                    <td class="tth">{{ ts('CUSTOMERNAME') }}</td>
                    <td class="ttd">
                        <input type="text" name="first_name" value="{{ $data->first_name ?: old('first_name') }}" class="form-control">
                    </td>
                    <td class="tth">{{ ts('phonenumber') }}</td>
                    <td class="ttd">
                        <div class=" input-group custom-control-inline">
                            <div class="input-group-prepend">
                                <select name="extension" class="form-control">
                                    @foreach(\App\Models\PhoneExtension::get(['id', 'phone_ext']) as $v)
                                        <option value="{{ $v->phone_ext }}" {{ ($data->extension == $v->phone_ext || old('phone_number')==$v->phone_ext ) ? 'selected' : '' }}>{{ $v->phone_ext }}</option>
                                    @endforeach
                                </select>
                            </div>
                            <input type="number" name="phone_number" value="{{ $data->phone_number ?: old('phone_number') }}" class="form-control">
                        </div>
                    </td>
                    <td class="tth">{{ ts('email') }}</td>
                    <td class="ttd">
                        <input type="email" name="email_address" value="{{ $data->email_address ?: old('email_address') }}" class="form-control">
                    </td>
                </tr>
                <tr>
                    <td class="tth">{{ ts('region') }}</td>
                    <td>
                        <select name="region_id" id="" class="form-control region_json" data-value="{{ $data->region_id ?: old('region_id') }}">
                            <option value="">{{ ts('select') }}</option>
                            <option value="{{ $data->region_id }}" selected>{{ ts('region_master.'.$data->region_id) }}</option>
                        </select>
                    </td>
                    <td class="tth">{{ ts('province') }}</td>
                    <td>
                        <select name="province_id" id="" class="form-control province_json" data-value="{{ $data->province_id ?: old('province_id') }}">
                            <option value="">{{ ts('select') }}</option>
                            <option value="{{ $data->province_id }}" selected>{{ ts('province_master.'.$data->province_id) }}</option>
                        </select>
                    </td>
                    <td class="tth">{{ ts('city') }}</td>
                    <td>
                        <select name="city" id="" class="form-control city_json" data-value="{{ $data->city ?: old('city') }}">
                            <option value="">{{ ts('select') }}</option>
                            <option value="{{ $data->city }}" selected>{{ ts('cities.'.$data->city) }}</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td class="tth">{{ ts('addresss') }}</td>
                    <td colspan="3">
                        <input type="text" name="address" value="{{ $data->address ?: old('address') }}" class="form-control">
                    </td>
                    <td class="tth">{{ ts('zip') }}</td>
                    <td>
                        <input type="text" name="addresss" value="{{ $data->zip ?: old('zip') }}" class="form-control">
                    </td>
                </tr>
                <tr>
                    <td colspan="6" class="tst">{{ ts('VEHICLEINFORMATION') }}</td>
                </tr>
                <tr>
                    <td class="tth">{{ ts('year') }}</td>
                    <td>
                        <select name="year_id" id="" class="form-control make_json_year" data-value="{{ $data->year_id ?: old('year_id') }}">
                            <option value="">{{ ts('select') }}</option>
                            <option value="{{ $data->year_id }}" selected>{{ $data->year_id }}</option>
                        </select>
                    </td>
                    <td class="tth">{{ ts('make') }}</td>
                    <td>
                        <select name="make_id" id="" class="form-control make_json_make" data-value="{{ $data->make_id ?: old('make_id') }}">
                            <option value="">{{ ts('select') }}</option>
                            <option value="{{ $data->make_id }}" selected>{{ ts('make_master.'.$data->make_id) }}</option>
                        </select>
                    </td>
                    <td class="tth">{{ ts('model') }}</td>
                    <td>
                        <select name="model_id" id="" class="form-control make_json_model" data-value="{{ $data->model_id ?: old('model_id') }}">
                            <option value="">{{ ts('select') }}</option>
                            <option value="{{ $data->model_id }}" selected>{{ ts('model_master.'.$data->model_id) }}</option>
                        </select>
                        {{--<input type="text" name="model_id" value="{{ $data->model_id ?: old('model_id') }}" class="form-control" >--}}
                    </td>
                </tr>
                <tr>
                    <td class="tth">{{ ts('licenseplate') }}</td>
                    <td>
                        <input type="text" name="license_plate" value="{{ $data->license_plate ?: old('license_plate') }}" class="form-control" >
                    </td>
                    <td class="tth">{{ ts('vinnumber') }}</td>
                    <td colspan="3">
                        <input type="text" name="vin_number" value="{{ $data->vin_number ?: old('vin_number') }}" class="form-control" >
                    </td>
                </tr>
                <tr>
                    <td colspan="6" class="tst">{{ ts('INSTALLATIONINFORMATION') }}</td>
                </tr>
                <tr>
                    <td class="tth">{{ ts('precutid') }}</td>
                    <td class="ttd">
                        <select name="pre_id" id="" class="form-control" onchange="getPrecutDetail()">
                            @if(session('admin.user_type') == 2)
                                @foreach(getDPDs(session('admin.id')) as $v)
                                    <option value="{{ @$v->id }}" {{ ($data->pre_id == @$v->id || request('pre_id')==@$v->id) ? 'selected' : '' }}>{{ @$v->precut_id }}</option>
                                @endforeach
                            @endif
                        </select>
                    </td>
                    <td class="tth">{{ ts('distributor') }}</td>
                    <td>
                        <input type="text" class="form-control sdjc" disabled name="sdjc" value="{{ getDJc($data->user_id) }}">
                    </td>
                    <td class="tth">{{ ts('qudao') }}</td>
                    <td>
                        <div class="input-group">
                            <input type="number" value="{{ $data->user_id }}" name="user_id" hidden>
                            <select class="form-control roll_user_id" name="user_id" disabled>
                                <option value="{{ $data->user_id }}">{{ getJc($data->user_id) }}</option>
                            </select>
                        </div>
                    </td>
                    {{--<td colspan="2" class="text-danger">
                        {{ ts('wcit2') }}
                    </td>--}}
                </tr>
                <tr>
                    <td class="tth">{{ ts('INSTALLERNAME') }}</td>
                    <td>
                        <input type="text" name="installer_name" value="{{ $data->installer_name ?: old('installer_name') }}" class="form-control" >
                    </td>
                    <td class="tth">{{ ts('INSTALLATIONDATE') }}</td>
                    <td>
                        <div class="input-group">
                            <input type="text" name="installation_date" value="{{ $data->installation_date ?: old('installation_date') }}" class="form-control flatpickr-ymdhis" data-max="{{ date('Y-m-d H:i:s') }}">
                            <div class="input-group-prepend">
                                <span class="btn btn-primary fkr-clear"><i class="fa fa-times"></i></span>
                            </div>
                        </div>
                    </td>
                    <td class="tth">{{ ts('INSTALLERPRICE') }}</td>
                    <td>
                        <input type="text" name="installation_price" value="{{ $data->installation_price ?: old('installation_price') }}" class="form-control" >
                    </td>
                </tr>
                <tr>
                    <td colspan="6" class="tst">{{ ts('INSTALLATIONPICTURE') }}</td>
                </tr>
                <tr>
                    <td colspan="6" class="ttt p-3">
                        <x-warranty-image-upload :warranty="$data"></x-warranty-image-upload>
                        {{--@include('admin.components.aztp-tb')--}}
                    </td>
                </tr>
                <tr>
                    <td colspan="6" class="tst">{{ ts('VEHICLECOVERAGE') }}</td>
                </tr>
                <tr>
                    <td colspan="6" class="ttt p-0">
                        @include('admin.subview.coverage', ['coverages' => @$coverages, 'is_precut'=>1])
                    </td>
                </tr>
                <tr>
                    <td colspan="6" class="tst">{{ ts('BCSM') }}</td>
                </tr>
                <tr>
                    <td colspan="6" height="auto">
                        <textarea name="additional_comments"  height="auto" rows="6" id="" class="form-control">{{ @$data->additional_comments ?: old('additional_comments') }}</textarea>
                    </td>
                </tr>
                </tbody>
            </table>

            <div class="mt-4">
                <button class="btn btn-primary">{{ ts('store') }}</button>
            </div>
        </form>
    </div>

@endsection


@section('script')
    <script>
        function getPrecutDetail() {
            var id = $('[name="pre_id"]').val()
            request.get('/admin/ajax/getPVC', {
                params: {
                    id: id,
                }
            }).then(function (d) {
                var obj = d.data;
                var jxs = d.jxs;
                initCoverageRowsV2(obj);
                $('[name="user_id"]').val(jxs.user_id)
                $('input[name="sdjc"]').val(jxs.sdmc)
                $('select[name="user_id"]').empty().append(makeSelectOptionsOnly([{label: jxs.jxsmc, value: jxs.user_id}]))
            })
        }
        $(document).ready(function () {
            getPrecutDetail();
        })
    </script>
@endsection